import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
import org.springframework.security.config.core.GrantedAuthorityDefaults;
import org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.access.channel.SecureChannelProcessor;
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;

import java.security.Principal;

public class Test {
//    UsernamePasswordAuthenticationFilter
//    GrantedAuthorityDefaults
//    org.springframework.security.access.vote.RoleVoter

    public String test() {

//        UserDetails
//        Authentication
//        GrantedAuthority
//        SecureChannelProcessor

        String username = SecurityContextHolder.getContext().getAuthentication().getName();

        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        if (principal instanceof UserDetails) {

            return ((UserDetails) principal).getUsername();

        }

        if (principal instanceof Principal) {

            return ((Principal) principal).getName();

        }

//        MethodSecurityMetadataSourceAdvisor

//        MethodSecurityExpressionHandler

//        GlobalMethodSecurityConfiguration

//        GlobalMethodSecurityBeanDefinitionParser
//        FilterSecurityInterceptor
//        AbstractPreAuthenticatedProcessingFilter
//        FilterSecurityInterceptor

//        DefaultMethodSecurityExpressionHandler
        return String.valueOf(principal);
    }
}

